<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('基础抽取列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>编码：</label>
                                <input type="text" name="cd"/>
                            </li>
                            <li>
                                <label>数据源：</label>
                                <select name="idDb" th:with="type=${@baseDbService.selectAll()}">
                                    <option value=""></option>
                                    <option th:each="item : ${type}" th:text="${item.na}" th:value="${item.idDb}"></option>
                                </select>
                            </li>
                            <li>
                                <label>启用标志：</label>
                                <select name="fgAct">
                                    <option value=""></option>
                                    <option value=1>启用</option>
                                    <option value=0>停用</option>
                                </select>
                            </li>
                            <li>
                                <label>抽取分类：</label>
                                <select name="sdDrawcls" th:with="type=${@baseSd.getItem('draw_cls')}">
                                    <option value=""></option>
                                    <option th:each="item : ${type}" th:text="${item.na}" th:value="${item.cd}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "etl/base";
        var sdSysData = [[${@baseSd.getItem('hos_sys')}]];
        var drawClsData = [[${@baseSd.getItem('draw_cls')}]];
        var dbData = [[${@baseDbService.selectAll()}]];
        function createTable(idDrawBase,na,cdTbTar) {

            var btn = ['<i class="fa fa-check"></i> 建表', '<i class="fa fa-close"></i> 关闭'];
            var options = {
                title: '创建表('+cdTbTar+")",
                width: "900",
                height: "720",
                url: prefix+"/createTb/"+idDrawBase,
                btn: btn,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
            //$.modal.open("创建基础表("+na+")", prefix+"/createTb/"+idDrawBase);
        }
        function doSubmit(index, layero) {
            var arr = this.url.split("/");
            $.ajax({
                url: prefix + '/execTableDDLColumns/'+arr[arr.length-1],
                type: 'get',
                success: function (data1) {
                    if (data1.code == 0) {

                        location.reload();
                        $.modal.closeAll();
                        $.modal.alertSuccess('执行成功！');
                    } else {
                        $.modal.alertError("创建失败，原因是"+data1.msg);
                    }
                }
            });
        }
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "基础抽取",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'idDrawBase',
                    title: '',
                    visible: false
                },
                {
                    field: 'cd',
                    title: '编码'
                },
                {
                    field: 'na',
                    title: '名称'
                },
                {
                    field: 'sdSys',
                    title: '系统',
                    formatter: function(value, item, index) {
                        return $.table.selectSdNaByCd(sdSysData, item.sdSys);
                    }
                },
                {
                    field: 'idDb',
                    title: '数据源'
                },
                {
                    field: 'fgAct',
                    title: '启用标志',
                    formatter: function(value, item, index) {
                        if(item.fgAct==1) {
                            return "启用";
                        } else {
                            return "停用"
                        }
                    }
                },
                {
                    field: 'sdDrawcls',
                    title: '抽取分类',
                    formatter: function(value, item, index) {
                        return $.table.selectSdNaByCd(drawClsData, item.sdDrawcls);
                    }
                },
                {
                    field: 'cdTbTar',
                    title: '目标表'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.idDrawBase + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        debugger;
                        if(row.fgTbCre==1) {
                            actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="createTable(\'' + row.idDrawBase + '\',\''+row.na+'\',\''+row.cdTbTar+'\')"><i class="fa fa-list-ul"></i>建表</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.idDrawBase + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>